package com.yixun.lbx.controller.productManagement;

import com.yixun.lbx.entity.ProDetail;
import com.yixun.lbx.service.ProductInfoServie;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;

@Controller
@RequestMapping("/sys_pm")
public class Pm_ViewController {
    /*TODO================产品管理==============================================================*/
    /*
     * 产品管理 > 产品信息
     * */
    @GetMapping("/sys_productInfo")
    public String goProductInfo() {
        return "/lbx/productManagement/sys_productInfo";
    }


    /*
     * 产品管理 > 产量管理
     * */
    @GetMapping("/sys_yield")
    public String goYield() {
        return "/lbx/productManagement/sys_yield";
    }

    /*
     * 产品管理 > 检测信息
     * */
    @GetMapping("/sys_detectInfo")
    public String goDetectInfo() {
        return "/lbx/productManagement/sys_detectInfo";
    }
    @Resource
    private ProductInfoServie infoService;
    @RequestMapping("/goDetail/{encryptId}")
    public String goDetail(@PathVariable String encryptId, Model model,HttpServletResponse res){
        String[] split = encryptId.split("_");
        long buildTime = Long.parseLong(split[0]);
        long nowTime = new Date().getTime();
        if (buildTime - nowTime < 1000*60){
            
            ProDetail proDetail = infoService.goProductDetail(split[1]);
            System.out.println(proDetail.getProductImages());
            model.addAttribute("productDetails",proDetail);
            return "/lbx/productManagement/productDetails";
        }else {
            try {
                res.getWriter().print("二维码失效，请重新生成后再试");
                res.getWriter().close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}
